home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-10-31 | 55.5 KB | 1,440 lines |
- Newsgroups: comp.sources.misc
- From: daveg@synaptics.com (David Gillespie)
- Subject: v24i079: gnucalc - GNU Emacs Calculator, v2.00, Part31/56
- Message-ID: <1991Oct31.214412.2242@sparky.imd.sterling.com>
- X-Md4-Signature: 94894bc0ce5693b5d214b3d54e153be0
- Date: Thu, 31 Oct 1991 21:44:12 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: daveg@synaptics.com (David Gillespie)
- Posting-number: Volume 24, Issue 79
- Archive-name: gnucalc/part31
- Environment: Emacs
- Supersedes: gmcalc: Volume 13, Issue 27-45
-
- ---- Cut Here and unpack ----
- #!/bin/sh
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file calc.texinfo continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 31; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping calc.texinfo'
- else
- echo 'x - continuing file calc.texinfo'
- sed 's/^X//' << 'SHAR_EOF' >> 'calc.texinfo' &&
- X
- @node The Standard Interface, Quick Mode Overview, Starting Calc, Using Calc
- @subsection The Standard Calc Interface
- X
- @noindent
- Calc's standard interface acts like a traditional RPN calculator,
- operated by the normal Emacs keyboard. When you type @kbd{M-# c}
- to start the Calculator, the Emacs screen splits into two windows
- with the file you were editing on top and Calc on the bottom.
- X
- @group
- @iftex
- @advance@hsize20pt
- @end iftex
- @smallexample
- X
- ...
- --**-Emacs: myfile (Fundamental)----All----------------------
- --- Emacs Calculator Mode --- |Emacs Calc Mode v2.00...
- 2: 17.3 | 17.3
- 1: -5 | 3
- X . | 2
- X | 4
- X | * 8
- X | ->-5
- X |
- --%%-Calc: 12 Deg (Calculator)----All----- --%%-Emacs: *Calc Trail*
- @end smallexample
- @end group
- X
- In this figure, the mode-line for @file{myfile} has moved up and the
- ``Calculator'' window has appeared below it. As you can see, Calc
- actually makes two windows side-by-side. The lefthand one is
- called the @dfn{stack window} and the righthand one is called the
- @dfn{trail window.} The stack holds the numbers involved in the
- calculation you are currently performing. The trail holds a complete
- record of all calculations you have done. In a desk calculator with
- a printer, the trail corresponds to the paper tape that records what
- you do.
- X
- In this case, the trail shows that four numbers (17.3, 3, 2, and 4)
- were first entered into the Calculator, then the 2 and 4 were
- multiplied to get 8, then the 3 and 8 were subtracted to get @i{-5}.
- (The @samp{>} symbol shows that this was the most recent calculation.)
- The net result is the two numbers 17.3 and @i{-5} sitting on the stack.
- X
- Most Calculator commands deal explicitly with the stack only, but
- there is a set of commands that allow you to search back through
- the trail and retrieve any previous result.
- X
- Calc commands use the digits, letters, and punctuation keys.
- Shifted (i.e., upper-case) letters are different from lowercase
- letters. Some letters are @dfn{prefix} keys that begin two-letter
- commands. For example, @kbd{e} means ``enter exponent'' and shifted
- @kbd{E} means @cite{e^x}. With the @kbd{d} (``display modes'') prefix
- the letter ``e'' takes on very different meanings: @kbd{d e} means
- ``engineering notation'' and @kbd{d E} means ``@dfn{eqn} language mode.''
- X
- There is nothing stopping you from switching out of the Calc
- window and back into your editing window, say by using the Emacs
- @w{@kbd{C-x o}} (@code{other-window}) command. When the cursor is
- inside a regular window, Emacs acts just like normal. When the
- cursor is in the Calc stack or trail windows, keys are interpreted
- as Calc commands.
- X
- When you quit by pressing @kbd{M-# c} a second time, the Calculator
- windows go away but the actual Stack and Trail are not gone, just
- hidden. When you press @kbd{M-# c} once again you will get the
- same stack and trail contents you had when you last used the
- Calculator.
- X
- The Calculator does not remember its state between Emacs sessions.
- Thus if you quit Emacs and start it again, @kbd{M-# c} will give you
- a fresh stack and trail. There is a command (@kbd{m m}) that lets
- you save your favorite mode settings between sessions, though.
- One of the things it saves is which user interface (standard or
- Keypad) you last used; otherwise, a freshly started Emacs will
- always treat @kbd{M-# M-#} the same as @kbd{M-# c}.
- X
- The @kbd{q} key is another equivalent way to turn the Calculator off.
- X
- If you type @kbd{M-# b} first and then @kbd{M-# c}, you get a
- full-screen version of Calc (@code{full-calc}) in which the stack and
- trail windows are still side-by-side but are now as tall as the whole
- Emacs screen. When you press @kbd{q} or @kbd{M-# c} again to quit,
- the file you were editing before reappears. The @kbd{M-# b} key
- switches back and forth between ``big'' full-screen mode and the
- normal partial-screen mode.
- X
- Finally, @kbd{M-# o} (@code{calc-other-window}) is like @kbd{M-# c}
- except that the Calc window is not selected. The buffer you were
- editing before remains selected instead. @kbd{M-# o} is a handy
- way to switch out of Calc momentarily to edit your file; type
- @kbd{M-# c} to switch back into Calc when you are done.
- X
- @node Quick Mode Overview, Keypad Mode Overview, The Standard Interface, Using Calc
- @subsection Quick Mode (Overview)
- X
- @noindent
- @dfn{Quick Mode} is a quick way to use Calc when you don't need the
- full complexity of the stack and trail. To use it, type @kbd{M-# q}
- (@code{quick-calc}).
- X
- Quick Mode is very simple: It prompts you to type any formula in
- standard algebraic notation (like @samp{4 - 2/3}) and then displays
- the result at the bottom of the Emacs screen (@i{3.33333333333}
- in this case). You are then back in the same editing buffer you
- were in before, ready to continue editing or to type @kbd{M-# q}
- again to do another quick calculation. The result of the calculation
- will also be in the Emacs ``kill ring'' so that a @kbd{C-y} command
- at this point will yank the result into your editing buffer.
- X
- @c [fix-ref Quick Calculator mode]
- @xref{Quick Calculator}, for further information.
- X
- @node Keypad Mode Overview, Standalone Operation, Quick Mode Overview, Using Calc
- @subsection Keypad Mode (Overview)
- X
- @noindent
- @dfn{Keypad Mode} is a mouse-based interface to the Calculator.
- It is designed for use with the X window system. If you don't
- have X, you will have to operate keypad mode with your arrow
- keys (which is probably more trouble than it's worth).
- X
- Type @kbd{M-# k} to turn Keypad Mode on or off. Once again you
- get two new windows, this time on the righthand side of the screen
- instead of at the bottom. The upper window is the familiar Calc
- Stack; the lower window is a picture of a typical calculator keypad.
- X
- @tex
- \dimen0=\pagetotal%
- \advance \dimen0 by 24\baselineskip%
- \ifdim \dimen0>\pagegoal \vfill\eject \fi%
- @end tex
- @smallexample
- X |--- Emacs Calculator Mode ---
- X |2: 17.3
- X |1: -5
- X | .
- X |--%%-Calc: 12 Deg (Calcul
- X |----+-----Calc 2.00-----+----1
- X |FLR |CEIL|RND |TRNC|CLN2|FLT |
- X |----+----+----+----+----+----|
- X | LN |EXP | |ABS |IDIV|MOD |
- X |----+----+----+----+----+----|
- X |SIN |COS |TAN |SQRT|y^x |1/x |
- X |----+----+----+----+----+----|
- X | ENTER |+/- |EEX |UNDO| <- |
- X |-----+---+-+--+--+-+---++----|
- X | INV | 7 | 8 | 9 | / |
- X |-----+-----+-----+-----+-----|
- X | HYP | 4 | 5 | 6 | * |
- X |-----+-----+-----+-----+-----|
- X |EXEC | 1 | 2 | 3 | - |
- X |-----+-----+-----+-----+-----|
- X | OFF | 0 | . | PI | + |
- X |-----+-----+-----+-----+-----+
- @end smallexample
- @iftex
- @begingroup
- @ifdim@hsize=5in
- @vskip-3.7in
- @advance@hsize-2.2in
- @else
- @vskip-3.95in
- @advance@hsize-3.05in
- @advance@vsize.1in
- @fi
- @end iftex
- X
- Keypad Mode is much easier for beginners to learn, because there
- is no need to memorize lots of obscure key sequences. But not all
- commands in regular Calc are available on the Keypad. You can
- always switch the cursor into the Calc stack window to use
- standard Calc commands if you need. Serious Calc users, though,
- often find they prefer the standard interface over Keypad Mode.
- X
- To operate the Calculator, just click on the ``buttons'' of the
- keypad using your left mouse button. To enter the two numbers
- shown here you would click @w{@kbd{1 7 .@: 3 ENTER 5 +/- ENTER}}; to
- add them together you would then click @kbd{+} (to get 12.3 on
- the stack).
- X
- If you click the right mouse button, the top three rows of the
- keypad change to show other sets of commands, such as advanced
- math functions, vector operations, and operations on binary
- numbers.
- X
- @iftex
- @endgroup
- @end iftex
- Because Keypad Mode doesn't use the regular keyboard, Calc leaves
- the cursor in your original editing buffer. You can type in
- this buffer in the usual way while also clicking on the Calculator
- keypad. One advantage of Keypad Mode is that you don't need an
- explicit command to switch between editing and calculating.
- X
- If you press @kbd{M-# b} first, you get a full-screen Keypad Mode
- (@code{full-calc-keypad}) with three windows: The keypad in the lower
- left, the stack in the lower right, and the trail on top.
- X
- @c [fix-ref Keypad Mode]
- @xref{Keypad Mode}, for further information.
- X
- @node Standalone Operation, Embedded Mode Overview, Keypad Mode Overview, Using Calc
- @subsection Standalone Operation
- X
- @noindent
- If you are not in Emacs at the moment but you wish to use Calc,
- you must start Emacs first. If all you want is to run Calc, you
- can give the commands:
- X
- @example
- emacs -f full-calc
- @end example
- X
- @noindent
- or
- X
- @example
- emacs -f full-calc-keypad
- @end example
- X
- @noindent
- which run a full-screen Calculator (as if by @kbd{M-# b M-# c}) or
- a full-screen X-based Calculator (as if by @kbd{M-# b M-# k}).
- In standalone operation, quitting the Calculator (by pressing
- @kbd{q} or clicking on the keypad @key{EXIT} button) quits Emacs
- itself.
- X
- @node Embedded Mode Overview, Other M-# Commands, Standalone Operation, Using Calc
- @subsection Embedded Mode (Overview)
- X
- @noindent
- @dfn{Embedded Mode} is a way to use Calc directly from inside an
- editing buffer. Suppose you have a formula written as part of a
- document like this:
- X
- @group
- @smallexample
- The derivative of
- X
- X ln(ln(x))
- X
- is
- @end smallexample
- @end group
- X
- @noindent
- and you wish to have Calc compute and format the derivative for
- you and store this derivative in the buffer automatically. To
- do this with Embedded Mode, first copy the formula down to where
- you want the result to be:
- X
- @group
- @smallexample
- The derivative of
- X
- X ln(ln(x))
- X
- is
- X
- X ln(ln(x))
- @end smallexample
- @end group
- X
- Now, move the cursor onto this new formula and press @kbd{M-# e}.
- Calc will read the formula (using the surrounding blank lines to
- tell how much text to read), then push this formula (invisibly)
- onto the Calc stack. The cursor will stay on the formula in the
- editing buffer, but the buffer's mode line will change to look
- like the Calc mode line (with mode indicators like @samp{12 Deg}
- and so on). Even though you are still in your editing buffer,
- the keyboard now acts like the Calc keyboard, and any new result
- you get is copied from the stack back into the buffer. To take
- the derivative, you would type @kbd{a d x @key{RET}}.
- X
- @group
- @smallexample
- The derivative of
- X
- X ln(ln(x))
- X
- is
- X
- 1 / ln(x) x
- @end smallexample
- @end group
- X
- To make this look nicer, you might want to press @kbd{d =} to center
- the formula, and even @kbd{d B} to use ``big'' display mode.
- X
- @group
- @smallexample
- The derivative of
- X
- X ln(ln(x))
- X
- is
- % [calc-mode: justify: center]
- % [calc-mode: language: big]
- X
- X 1
- X -------
- X ln(x) x
- @end smallexample
- @end group
- X
- Calc has added annotations to the file to help it remember the modes
- that were used for this formula. They are formatted like comments
- in the @TeX{} typesetting language, just in case you are using @TeX{}.
- (In this example @TeX{} is not being used, so you might want to move
- these comments up to the top of the file or otherwise put them out
- of the way.)
- X
- As an extra flourish, we can add an equation number using a
- righthand label: Type @kbd{d @} (1) RET}.
- X
- @group
- @smallexample
- % [calc-mode: justify: center]
- % [calc-mode: language: big]
- % [calc-mode: right-label: " (1)"]
- X
- X 1
- X ------- (1)
- X ln(x) x
- @end smallexample
- @end group
- X
- To leave Embedded Mode, type @kbd{M-# e} again. The mode line
- and keyboard will revert to the way they were before. (If you have
- actually been trying this as you read along, you'll want to press
- @kbd{M-# 0} [with the digit zero] now to reset the modes you changed.)
- X
- The related command @kbd{M-# w} operates on a single word, which
- generally means a single number, inside text. It uses any
- non-numeric characters rather than blank lines to delimit the
- formula it reads. Here's an example of its use:
- X
- @smallexample
- A slope of one-third corresponds to an angle of 1 degrees.
- @end smallexample
- X
- Place the cursor on the @samp{1}, then type @kbd{M-# w} to enable
- Embedded Mode on that number. Now type @kbd{3 /} (to get one-third),
- and @kbd{I T} (the Inverse Tangent converts a slope into an angle),
- then @kbd{M-# w} again to exit Embedded mode.
- X
- @smallexample
- A slope of one-third corresponds to an angle of 18.4349488229 degrees.
- @end smallexample
- X
- @c [fix-ref Embedded Mode]
- @xref{Embedded Mode}, for full details.
- X
- @node Other M-# Commands, , Embedded Mode Overview, Using Calc
- @subsection Other @kbd{M-#} Commands
- X
- @noindent
- Two more Calc-related commands are @kbd{M-# g} and @kbd{M-# r},
- which ``grab'' data from a selected region of a buffer into the
- Calculator. The region is defined in the usual Emacs way, by
- a ``mark'' placed at one end of the region, and the Emacs
- cursor or ``point'' placed at the other.
- X
- The @kbd{M-# g} command reads the region in the usual left-to-right,
- top-to-bottom order. The result is packaged into a Calc vector
- of numbers and placed on the stack. Calc (in its standard
- user interface) is then started. Type @kbd{v u} if you want
- to unpack this vector into separate numbers on the stack. Also,
- @kbd{C-u M-# g} interprets the region as a single number or
- formula.
- X
- The @kbd{M-# r} command reads a rectangle, with the point and
- mark defining opposite corners of the rectangle. The result
- is a matrix of numbers on the Calculator stack.
- X
- Complementary to these is @kbd{M-# y}, which ``yanks'' the
- value at the top of the Calc stack back into an editing buffer.
- If you type @w{@kbd{M-# y}} while in such a buffer, the value is
- yanked at the current position. If you type @kbd{M-# y} while
- in the Calc buffer, Calc makes an educated guess as to which
- editing buffer you want to use. The Calc window does not have
- to be visible in order to use this command, as long as there
- is something on the Calc stack.
- X
- Here, for reference, is the complete list of @kbd{M-#} commands.
- The shift, control, and meta keys are ignored for the keystroke
- following @kbd{M-#}.
- X
- @noindent
- Commands for turning Calc on and off:
- X
- @table @kbd
- @item #
- Turn Calc on or off, employing the same user interface as last time.
- X
- @item C
- Turn Calc on or off using its standard bottom-of-the-screen
- interface. If Calc is already turned on but the cursor is not
- in the Calc window, move the cursor into the window.
- X
- @item O
- Same as @kbd{C}, but don't select the new Calc window. If
- Calc is already turned on and the cursor is in the Calc window,
- move it out of that window.
- X
- @item B
- Control whether @kbd{M-# c} and @kbd{M-# k} use the full screen.
- X
- @item Q
- Use Quick Mode for a single short calculation.
- X
- @item K
- Turn Calc Keypad mode on or off.
- X
- @item E
- Turn Calc Embedded mode on or off at the current formula.
- X
- @item J
- Turn Calc Embedded mode on or off, select the interesting part.
- X
- @item W
- Turn Calc Embedded mode on or off at the current word (number).
- X
- @item Z
- Turn Calc on in a user-defined way, as defined by a @kbd{Z I} command.
- X
- @item X
- Quit Calc; turn off standard, Keypad, or Embedded mode if on.
- (This is like @kbd{q} or @key{OFF} inside of Calc.)
- @end table
- @iftex
- @sp 2
- @end iftex
- X
- @group
- @noindent
- Commands for moving data into and out of the Calculator:
- X
- @table @kbd
- @item G
- Grab the region into the Calculator as a vector.
- X
- @item R
- Grab the rectangular region into the Calculator as a matrix.
- X
- @item :
- Grab the rectangular region and compute the sums of its columns.
- X
- @item _
- Grab the rectangular region and compute the sums of its rows.
- X
- @item Y
- Yank a value from the Calculator into the current editing buffer.
- @end table
- @iftex
- @sp 2
- @end iftex
- @end group
- X
- @group
- @noindent
- Commands for use with Embedded Mode:
- X
- @table @kbd
- @item A
- ``Activate'' the current buffer. Locate all formulas that
- contain @samp{:=} or @samp{=>} symbols and record their locations
- so that they can be updated automatically as variables are changed.
- X
- @item D
- Duplicate the current formula immediately below and select
- the duplicate.
- X
- @item F
- Insert a new formula at the current point.
- X
- @item N
- Move the cursor to the next active formula in the buffer.
- X
- @item P
- Move the cursor to the previous active formula in the buffer.
- X
- @item U
- Update (i.e., as if by the @kbd{=} key) the formula at the current point.
- X
- @item `
- Edit (as if by @code{calc-edit}) the formula at the current point.
- @end table
- @iftex
- @sp 2
- @end iftex
- @end group
- X
- @group
- @noindent
- Miscellaneous commands:
- X
- @table @kbd
- @item I
- Run the Emacs Info system to read the Calc manual.
- (This is the same as @kbd{h i} inside of Calc.)
- X
- @item T
- Run the Emacs Info system to read the Calc Tutorial. This uses
- @kbd{M-# i} and @kbd{M-# c} to start the Info system and make
- a Calc window, then switches the Info system to the start
- of the tutorial.
- X
- @item S
- Run the Emacs Info system to read the Calc Summary.
- X
- @item L
- Load Calc entirely into memory. (Normally the various parts
- are loaded only as they are needed.)
- X
- @item M
- Read a region of written keystroke names (like @samp{C-n a b c RET})
- and record them as the current keyboard macro.
- X
- @item 0
- (This is the ``zero'' digit key.) Reset the Calculator to
- its default state: Empty stack, and default mode settings.
- With any prefix argument, reset everything but the stack.
- @end table
- @end group
- X
- @node Demonstration of Calc, New for Calc 2.00, Using Calc, Getting Started
- @section A Demonstration of Calc
- X
- @noindent
- This section will show some typical small problems being solved with
- Calc. The focus is more on demonstration than explanation, but
- everything you see here will be covered more thoroughly in the
- Tutorial.
- X
- To begin, type @kbd{M-# c} to start the Calculator. Be sure to type
- all the sample input exactly, especially the difference between
- lower-case and upper-case letters. Remember, @kbd{RET}, @kbd{TAB},
- @kbd{DEL}, and @kbd{SPC} are the Return, Tab, Delete, and Space keys.
- X
- @strong{RPN calculation.} In RPN, you type the input number(s) first,
- then the command to operate on the numbers.
- X
- @noindent
- Type @kbd{2 RET 3 + Q} to compute @c{$\sqrt{2+3}$}
- @asis{the square root of 2+3}.
- X
- @noindent
- Type @kbd{P 2 ^} to compute @c{$\pi^2$}
- @asis{the value of `pi' squared}.
- X
- @noindent
- Type @kbd{TAB} to exchange the order of these two results.
- X
- @noindent
- Type @kbd{- I H S} to subtract these results and compute the Inverse
- Hyperbolic sine of the difference, 2.72996136574.
- X
- @noindent
- Type @kbd{DEL} to erase this result.
- X
- @strong{Algebraic calculation.} To enter a calculation using
- conventional ``algebraic'' notation, use the apostrophe key.
- X
- @noindent
- Type @kbd{' sqrt(2+3) RET} to compute @c{$\sqrt{2+3}$}
- @asis{the square root of 2+3}.
- X
- @noindent
- Type @kbd{' pi^2 RET} to enter @c{$\pi^2$}
- @asis{`pi' squared}. To evaluate this symbolic
- formula as a number, type @kbd{=}.
- X
- @noindent
- Type @kbd{' arcsinh($ - $$) RET} to subtract the second-most-recent
- result from the most-recent and compute the Inverse Hyperbolic sine.
- X
- @strong{Keypad mode.} If you are using the X window system, press
- @w{@kbd{M-# k}} to get Keypad mode.
- X
- @noindent
- Click on the @key{2}, @key{ENTER}, @key{3}, @key{+}, and @key{SQRT}
- ``buttons'' using your left mouse button.
- X
- @noindent
- Click on @key{PI}, @key{2}, and @key{y^x}.
- X
- @noindent
- Click on @key{INV}, then @key{ENTER} to swap the two results.
- X
- @noindent
- Click on @key{-}, @key{INV}, @key{HYP}, and @key{SIN}.
- X
- @noindent
- Click on @key{<-} to erase the result, then click @key{OFF} to turn
- the Keypad Calculator off.
- X
- @strong{Grabbing data.} Type @kbd{M-# x} if necessary to exit Calc.
- Now select the following numbers as an Emacs region: ``Mark'' the
- front of the list by typing control-@kbd{SPC} or control-@kbd{@@} there,
- then move to the other end of the list. Now type @kbd{M-# g} to ``grab''
- these numbers into Calc.
- X
- @group
- @example
- 1.23 1.97
- 1.6 2
- 1.19 1.08
- @end example
- @end group
- X
- @noindent
- The result @samp{[1.23, 1.97, 1.6, 2, 1.19, 1.08]} is a Calc ``vector.''
- Type @w{@kbd{V R +}} to compute the sum of these numbers.
- X
- @noindent
- Type @kbd{U} to Undo this command, then type @kbd{V R *} to compute
- the product of the numbers.
- X
- @noindent
- You can also grab data as a rectangular matrix. Place the cursor on
- the upper-leftmost @samp{1} and set the mark, then move to just after
- the lower-right @samp{8} and press @kbd{M-# r}.
- X
- @noindent
- Type @kbd{v t} to transpose this @c{$3\times2$}
- @asis{3x2} matrix into a @c{$2\times3$}
- @asis{2x3} matrix. Type
- @w{@kbd{v u}} to unpack the rows into two separate vectors. Now type
- @w{@kbd{V R + TAB V R +}} to compute the sums of the two original columns.
- (There is also a special grab-and-sum-columns command, @kbd{M-# :}.)
- X
- @strong{Units conversion.} Units are entered algebraically.
- Type @w{@kbd{' 43 mi/hr RET}} to enter the quantity 43 miles-per-hour.
- Type @w{@kbd{u c km/hr RET}}. Type @w{@kbd{u c m/s RET}}.
- X
- @strong{Date arithmetic.} Type @kbd{t N} to get the current date and
- time. Type @kbd{90 +} to find the date 90 days from now. Type
- @kbd{' <25 dec 87> RET} to enter a date, then @kbd{- 7 /} to see how
- many weeks have passed since then.
- X
- @strong{Algebra.} Algebraic entries can include formulas
- or equations involving variables. Type @kbd{' [x + y = a, x y = 1] RET}
- to enter a pair of equations involving three variables. Type
- @kbd{a S x,y RET} to solve these equations for the variables @cite{x}
- and @cite{y}.
- X
- @noindent
- Type @kbd{d B} to view the solutions in more readable notation.
- Type @w{@kbd{d C}} to view them in C language notation, and @kbd{d T}
- to view them in the notation for the @TeX{} typesetting system.
- Type @kbd{d N} to return to normal notation.
- X
- @noindent
- Type @kbd{7.5 s l a RET} to let @cite{a = 7.5} in these formulas.
- X
- @strong{Help functions.} You can read about any command in the on-line
- manual. If you are reading this demonstration on-line, remember to type
- the letter @kbd{l}, then @kbd{M-# c}, to return here after each of these
- commands: @w{@kbd{h k t N}} to read about the @w{@kbd{t N}} command,
- @kbd{h f sqrt RET} to read about the @code{sqrt} function, and @kbd{h s}
- to read the Calc summary.
- X
- Press @kbd{DEL} repeatedly to remove any leftover results from the stack.
- X
- @node New for Calc 2.00, History and Acknowledgements, Demonstration of Calc, Getting Started
- @section New for Calc 2.00
- X
- If you are upgrading from Calc 1.07, you will find many new features and
- changes in this version of Calc. This section is a summary of the major
- areas of improvement, but it doesn't list every minor change. The
- @file{README.prev} file that comes with the Calc FTP distribution contains
- a more complete list of all changes that have appeared in every version
- of Calc.
- X
- @strong{Installation.} The installation procedure has been completely
- redone. Calc is now compatible with the Unix @code{make} utility: A
- single Unix command compiles and installs Calc and formats the on-line
- Info documentation. Calc is now much more forgiving about being moved
- to a new directory after being compiled.
- X
- @strong{Start-up.} The @kbd{M-#} key is now a prefix; followed by
- various letters, it allows quick access to several different Calc
- user interfaces and related functions, such as @code{quick-calc}
- and @code{calc-grab-region}. Quitting Calc now tries to preserve
- the old configuration of windows.
- X
- @strong{Display.} Language modes for @dfn{eqn} and Maple were added.
- Big mode now has many more special formats, such as square roots, sums,
- and fractions. Radix modes now work with floating-point numbers.
- Long lines in the display are broken more intelligently. ``Composition
- functions'' allow you to define your own special display formats. It
- is now possible to change display modes without redrawing the entire
- stack.
- X
- @strong{Keyboard.} The @kbd{M-DEL} key deletes the second-from-top
- stack element. The @kbd{@{} and @kbd{@}} keys scroll the stack display
- vertically. The @kbd{m t} command enables ``total'' algebraic mode,
- where algebraic entry is used all the time. The @kbd{s} (store)
- key has become a prefix key, with options for storing, recalling,
- exchanging, modifying, and editing variables. With an equation on the
- stack, ``store'' and ``let'' default to taking the variable name and
- value from the two sides of the equation. Matrix mapping modes for
- @kbd{V M} and @kbd{V R} have been replaced with a new system that is
- easier to remember and less error-prone, and a new notation for nameless
- functions has been introduced in place of @code{lambda} expressions.
- X
- @strong{Functions.} Several financial functions were added, as were a
- number of statistical functions. Least-squares curve fitting, including
- multilinear and many nonlinear models, is supported. Functions left
- unevaluated now actively report the problem rather than waiting for you
- to press @kbd{w}. Arithmetic now does overflow and underflow checking
- on all floating-point results. The @code{random} function can now be
- seeded by a user-specified value. New @code{gamma} and @code{phi}
- special constants complement @code{pi}, @code{e}, and @code{i}.
- X
- @strong{Data types.} Date forms, with several date arithmetic functions,
- were added. Fractions can be displayed with a fixed denominator. Calc
- now understands the concept of ``infinity,'' including infinite intervals.
- Error forms can now include complex numbers. Units have several new
- features, including composite units (@code{mi+ft+in}), automatic prefix
- adjustment as an option (@samp{3000 m} converts to @samp{3 km}), and a
- new-and-improved table of predefined units.
- X
- @strong{Algebra.} The equation solver can do many more kinds of equations,
- and can solve systems of equations. All roots of a polynomial can now be
- found numerically if symbolic methods fail. Many new polynomial operations
- exist, such as division, GCD, factorization, and partial fractions. The
- integrator now handles many common types of integrals, and numerical
- integration is also supported. Sums and products, including closed-form
- solutions and infinite sums in certain cases, are possible. Default
- simplifications have been improved in various ways, and are now fully
- documented. Simplification is now more careful about branch cuts.
- Declarations for variables are supported; variables can be declared real,
- positive, matrix or scalar, etc., allowing better simplification of
- formulas involving them.
- X
- @strong{Graphics.} Together with GNUPLOT 3.0, several new options exist
- including 3D graphs of functions or data. Plotting to an Emacs window
- using ``ASCII graphics'' is now supported, and there is a better interface
- for Tektronix graphics terminals.
- X
- @strong{Rewrite rules.} The variable @code{EvalRules} contains rules to
- be applied every time a formula is evaluated; this allows you to define
- your own functions or default simplifications using rewrites. The new
- notation @samp{@var{old} := @var{new} :: @var{condition}} is supported
- for rewrites. Operators @code{&&&}, @code{|||}, and @code{!!!} allow
- and/or/not combinations of rewrite patterns. Rewriting may be broken
- into multiple independent phases. The Calc Tutorial now has a section
- on rewrite rules.
- X
- @strong{Embedded mode.} It is now possible to run Calc on numbers and
- formulas directly inside your editing buffer. While a value is ``live,''
- regular Calc keystrokes operate on the value as if it were on the Calc
- stack.
- X
- @strong{Documentation.} The @kbd{h} key is now a prefix, with options
- for reading the manual or tutorial, or for looking up any key, command,
- function, or variable in the manual automatically. (Most regular Emacs
- @kbd{C-h f} documentation was removed to save space.) A complete
- ``summary'' appendix was added to the manual. Parts of the manual
- were rearranged or rewritten, particularly the ``Getting Started''
- chapter. Minor improvements were made throughout the manual.
- X
- @node History and Acknowledgements, , New for Calc 2.00, Getting Started
- @section History and Acknowledgements
- X
- @noindent
- Calc was originally started as a two-week project to occupy a lull
- in the author's schedule. Basically, a friend asked if I remembered
- the value of @c{$2^{32}$}
- @cite{2^32}. I didn't offhand, but I said, ``that's
- easy, just call up an @code{xcalc}.'' @code{Xcalc} duly reported
- that the answer to our question was @samp{4.294967e+09}---with no way to
- see the full ten digits even though we knew they were there in the
- program's memory! I was so annoyed, I vowed to write a calculator
- of my own, once and for all.
- X
- I chose Emacs Lisp, a) because I had always been curious about it
- and b) because, being only a text editor extension language after
- all, Emacs Lisp would surely reach its limits long before the project
- got too far out of hand.
- X
- To make a long story short, Emacs Lisp turned out to be a distressingly
- solid implementation of Lisp, and the humble task of calculating
- turned out to be more open-ended than one might have expected.
- X
- Emacs Lisp doesn't have built-in floating point math, so it had to be
- simulated in software. In fact, Emacs integers will only comfortably
- fit six decimal digits or so---not enough for a decent calculator. So
- I had to write my own high-precision integer code as well, and once I had
- this I figured that arbitrary-size integers were just as easy as large
- integers. Arbitrary floating-point precision was the logical next step.
- Also, since the large integer arithmetic was there anyway it seemed only
- fair to give the user direct access to it, which in turn made it practical
- to support fractions as well as floats. All these features inspired me
- to look around for other data types that might be worth having.
- X
- Around this time, my friend Rick Koshi showed me his nifty new HP-28
- calculator. It allowed the user to manipulate formulas as well as
- numerical quantities, and it could also operate on matrices. I decided
- that these would be good for Calc to have, too. And once things had
- gone this far, I figured I might as well take a look at serious algebra
- systems like Mathematica, Macsyma, and Maple for further ideas. Since
- these systems did far more than I could ever hope to implement, I decided
- to focus on rewrite rules and other programming features so that users
- could implement what they needed for themselves.
- X
- Rick complained that matrices were hard to read, so I put in code to
- format them in a 2D style. Once these routines were in place, Big mode
- was obligatory. Gee, what other language modes would be useful?
- X
- Scott Hemphill and Allen Knutson, two friends with a strong mathematical
- bent, contributed ideas and algorithms for a number of Calc features
- including modulo forms, primality testing, and float-to-fraction conversion.
- X
- Units were added at the eager insistence of Mass Sivilotti. Later,
- Ulrich Mueller at CERN and Przemek Klosowski at NIST provided invaluable
- expert assistance with the units table. As far as I can remember, the
- idea of using algebraic formulas and variables to represent units dates
- back to an ancient article in Byte magazine about muMath, an early
- algebra system for microcomputers.
- X
- Many people have contributed to Calc by reporting bugs and suggesting
- features, large and small. A few deserve special mention: Tim Peters,
- who helped develop the ideas that led to the selection commands, rewrite
- rules, and many other algebra features; @c{Fran\c cois}
- @asis{Francois} Pinard, who contributed
- an early prototype of the Calc Summary appendix as well as providing
- valuable suggestions in many other areas of Calc; Carl Witty, whose eagle
- eyes discovered many typographical and factual errors in the Calc manual;
- Tim Kay, who drove the development of Embedded mode; Ove Ewerlid, who
- made many suggestions relating the the algebra commands and contributed
- some code for polynomial operations; Randal Schwartz, who suggested the
- @code{calc-eval} function; Bob Chassell, who suggested the Calc Tutorial
- and exercises; and Juha Sarlin, who first worked out how to split Calc
- into quickly-loading parts.
- X
- @c Should these be expanded into more complete references?
- Among the books used in the development of Calc were Knuth's @emph{Art
- of Computer Programming} (especially volume II, @emph{Seminumerical
- Algorithms}); @emph{Numerical Recipes} by Press, Flannery, Teukolsky,
- and Vetterling; Bevington's @emph{Data Reduction and Error Analysis for
- the Physical Sciences}; @emph{Concrete Mathematics} by Graham, Knuth,
- and Patashnik; Steele's @emph{Common Lisp, the Language}; the @emph{CRC
- Standard Math Tables} (William H. Beyer, ed.); and Abramowitz and
- Stegun's venerable @emph{Handbook of Mathematical Functions}. I
- consulted the user's manuals for the HP-28 and HP-48 calculators, as
- well as for the programs Mathematica, SMP, Macsyma, Maple, MathCAD,
- Gnuplot, and others. Also, of course, Calc could not have been written
- without the excellent @emph{GNU Emacs Lisp Reference Manual}, by Bil
- Lewis and Dan LaLiberte.
- X
- Final thanks go to Richard Stallman, without whose fine implementations
- of the Emacs editor, language, and environment, Calc would have been
- finished in two weeks.
- X
- @c [tutorial]
- X
- @ifinfo
- @c This node is accessed by the `M-# t' command.
- @node Interactive Tutorial, , , Top
- @chapter Tutorial
- X
- @noindent
- Some brief instructions on using the Emacs Info system for this tutorial:
- X
- Press the space bar and Delete keys to go forward and backward in a
- section by screenfuls (or use the regular Emacs scrolling commands
- for this).
- X
- Press @kbd{n} or @kbd{p} to go to the Next or Previous section.
- If the section has a @dfn{menu}, press a digit key like @kbd{1}
- or @kbd{2} to go to a sub-section from the menu. Press @kbd{u} to
- go back up from a sub-section to the menu it is part of.
- X
- Exercises in the tutorial all have cross-references to the
- appropriate page of the ``answers'' section. Press @kbd{f}, then
- the exercise number, to see the answer to an exercise. After
- you have followed a cross-reference, you can press the letter
- @kbd{l} to return to where you were before.
- X
- You can press @kbd{?} at any time for a brief summary of Info commands.
- X
- Press @kbd{1} now to enter the first section of the Tutorial.
- X
- @menu
- * Tutorial::
- @end menu
- @end ifinfo
- X
- @node Tutorial, Introduction, Getting Started, Top
- @chapter Tutorial
- X
- @noindent
- This chapter explains how to use Calc and its many features, in
- a step-by-step, tutorial way. You are encouraged to run Calc and
- work along with the examples as you read (@pxref{Starting Calc}).
- If you are already familiar with advanced calculators, you may wish
- @c [not-split]
- to skip on to the rest of this manual.
- @c [when-split]
- @c to skip on to volume II of this manual, the @dfn{Calc Reference}.
- X
- @c [fix-ref Embedded Mode]
- This tutorial describes the standard user interface of Calc only.
- The ``Quick Mode'' and ``Keypad Mode'' interfaces are fairly
- self-explanatory. @xref{Embedded Mode}, for a description of
- the ``Embedded Mode'' interface.
- X
- @ifinfo
- The easiest way to read this tutorial on-line is to have two windows on
- your Emacs screen, one with Calc and one with the Info system. (If you
- have a printed copy of the manual you can use that instead.) Press
- @kbd{M-# c} to turn Calc on or to switch into the Calc window, and
- press @kbd{M-# i} to start the Info system or to switch into its window.
- Or, you may prefer to use the tutorial in printed form.
- @end ifinfo
- @iftex
- The easiest way to read this tutorial on-line is to have two windows on
- your Emacs screen, one with Calc and one with the Info system. (If you
- have a printed copy of the manual you can use that instead.) Press
- @kbd{M-# c} to turn Calc on or to switch into the Calc window, and
- press @kbd{M-# i} to start the Info system or to switch into its window.
- @end iftex
- X
- This tutorial is designed to be done in sequence. But the rest of this
- manual does not assume you have gone through the tutorial. The tutorial
- does not cover everything in the Calculator, but it touches on most
- general areas.
- X
- @ifinfo
- You may wish to print out a copy of the Calc Summary and keep notes on
- it as you learn Calc. @xref{Installation}, to see how to make a printed
- summary. @xref{Summary}.
- @end ifinfo
- @iftex
- The Calc Summary at the end of the reference manual includes some blank
- space for your own use. You may wish to keep notes there as you learn
- Calc.
- @end iftex
- X
- @menu
- * Basic Tutorial::
- * Arithmetic Tutorial::
- * Vector/Matrix Tutorial::
- * Types Tutorial::
- * Algebra Tutorial::
- * Programming Tutorial::
- X
- * Answers to Exercises::
- @end menu
- X
- @node Basic Tutorial, Arithmetic Tutorial, Tutorial, Tutorial
- @section Basic Tutorial
- X
- @noindent
- In this section, we learn how RPN and algebraic-style calculations
- work, how to undo and redo an operation done by mistake, and how
- to control various modes of the Calculator.
- X
- @menu
- * RPN Tutorial:: Basic operations with the stack.
- * Algebraic Tutorial:: Algebraic entry; variables.
- * Undo Tutorial:: If you make a mistake: Undo and the trail.
- * Modes Tutorial:: Common mode-setting commands.
- @end menu
- X
- @node RPN Tutorial, Algebraic Tutorial, Basic Tutorial, Basic Tutorial
- @subsection RPN Calculations and the Stack
- X
- @cindex RPN notation
- @ifinfo
- @noindent
- Calc normally uses RPN notation. You may be familiar with the RPN
- system from Hewlett-Packard calculators, FORTH, or PostScript.
- (Reverse Polish Notation, RPN, is named after the Polish mathematician
- Jan Lukasiewicz.)
- @end ifinfo
- @tex
- \noindent
- Calc normally uses RPN notation. You may be familiar with the RPN
- system from Hewlett-Packard calculators, FORTH, or PostScript.
- (Reverse Polish Notation, RPN, is named after the Polish mathematician
- Jan \L ukasiewicz.)
- @end tex
- X
- The central component of an RPN calculator is the @dfn{stack}. A
- calculator stack is like a stack of dishes. New dishes (numbers) are
- added at the top of the stack, and numbers are normally only removed
- from the top of the stack.
- X
- @cindex Operators
- @cindex Operands
- In an operation like @cite{2+3}, the 2 and 3 are called the @dfn{operands}
- and the @cite{+} is the @dfn{operator}. In an RPN calculator you always
- enter the operands first, then the operator. Each time you type a
- number, Calc adds or @dfn{pushes} it onto the top of the Stack.
- When you press an operator key like @kbd{+}, Calc @dfn{pops} the appropriate
- number of operands from the stack and pushes back the result.
- X
- Thus we could add the numbers 2 and 3 in an RPN calculator by typing:
- @kbd{2 @key{RET} 3 @key{RET} +}. (The @key{RET} key, Return, corresponds to
- the @key{ENTER} key on traditional RPN calculators.) Try this now if
- you wish; type @kbd{M-# c} to switch into the Calc window (you can type
- @kbd{M-# c} again or @kbd{M-# o} to switch back to the Tutorial window).
- The first four keystrokes ``push'' the numbers 2 and 3 onto the stack.
- The @kbd{+} key ``pops'' the top two numbers from the stack, adds them,
- and pushes the result (5) back onto the stack. Here's how the stack
- will look at various points throughout the calculation:@refill
- X
- @group
- @smallexample
- X . 1: 2 2: 2 1: 5 .
- X . 1: 3 .
- X .
- X
- X M-# c 2 RET 3 RET + DEL
- @end smallexample
- @end group
- X
- The @samp{.} symbol is a marker that represents the top of the stack.
- Note that the ``top'' of the stack is really shown at the bottom of
- the Stack window. This may seem backwards, but it turns out to be
- less distracting in regular use.
- X
- @cindex Stack levels
- @cindex Levels of stack
- The numbers @samp{1:} and @samp{2:} on the left are @dfn{stack level
- numbers}. Old RPN calculators always had four stack levels called
- @cite{x}, @cite{y}, @cite{z}, and @cite{t}. Calc's stack can grow
- as large as you like, so it uses numbers instead of letters. Some
- stack-manipulation commands accept a numeric argument that says
- which stack level to work on. Normal commands like @kbd{+} always
- work on the top few levels of the stack.@refill
- X
- @c [fix-ref Truncating the Stack]
- The Stack buffer is just an Emacs buffer, and you can move around in
- it using the regular Emacs motion commands. But no matter where the
- cursor is, even if you have scrolled the @samp{.} marker out of
- view, most Calc commands always move the cursor back down to level 1
- before doing anything. It is possible to move the @samp{.} marker
- upwards through the stack, temporarily ``hiding'' some numbers from
- commands like @kbd{+}. This is called @dfn{stack truncation} and
- we will not cover it in this tutorial; @pxref{Truncating the Stack},
- if you are interested.
- X
- You don't really need the second @key{RET} in @kbd{2 @key{RET} 3
- @key{RET} +}. That's because if you type any operator name or
- other non-numeric key when you are entering a number, the Calculator
- automatically enters that number and then does the requested command.
- Thus @kbd{2 @key{RET} 3 +} will work just as well.@refill
- X
- Examples in this tutorial will often omit @key{RET} even when the
- stack displays shown would only happen if you did press @key{RET}:
- X
- @group
- @smallexample
- 1: 2 2: 2 1: 5
- X . 1: 3 .
- X .
- X
- X 2 RET 3 +
- @end smallexample
- @end group
- X
- @noindent
- Here, after pressing @kbd{3} the stack would really show @samp{1: 2}
- with @samp{Calc:@: 3} in the minibuffer. In these situations, you can
- press the optional @key{RET} to see the stack as the figure shows.
- X
- (@bullet{}) @strong{Exercise 1.} (This tutorial will include exercises
- at various points. Try them if you wish. Answers to all the exercises
- are located at the end of the Tutorial chapter. Each exercise will
- include a cross-reference to its particular answer. If you are
- reading with the Emacs Info system, press @kbd{f} and the
- exercise number to go to the answer, then the letter @kbd{l} to
- return to where you were.)
- X
- @noindent
- Here's the first exercise: What will the keystrokes @kbd{1 @key{RET} 2
- @key{RET} 3 @key{RET} 4 + * -} compute? (@samp{*} is the symbol for
- multiplication.) Figure it out by hand, then try it with Calc to see
- if you're right. @xref{RPN Answer 1, 1}. (@bullet{})
- X
- (@bullet{}) @strong{Exercise 2.} Compute @c{$2\times4 + 7\times9.4 + {5\over4}$}
- @cite{2*4 + 7*9.5 + 5/4} using the
- stack. @xref{RPN Answer 2, 2}. (@bullet{})
- X
- The @key{DEL} key is called Backspace on some keyboards. It is
- whatever key you would use to correct a simple typing error when
- regularly using Emacs. The @key{DEL} key pops and throws away the
- top value on the stack. (You can still get that value back from
- the Trail if you should need it later on.) There are many places
- in this tutorial where we assume you have used @key{DEL} to erase the
- results of the previous example at the beginning of a new example.
- In the few places where it is really important to use @key{DEL} to
- clear away old results, the text will remind you to do so.
- X
- (It won't hurt to let things accumulate on the stack, except that
- whenever you give a display-mode-changing command Calc will have to
- spend a long time reformatting such a large stack.)
- X
- Since the @kbd{-} key is also an operator (it subtracts the top two
- stack elements), how does one enter a negative number? Calc uses
- the @kbd{_} (underscore) key to act like the minus sign in a number.
- So, typing @kbd{-5 @key{RET}} won't work because the @kbd{-} key
- will try to do a subtraction, but @kbd{_5 @key{RET}} works just fine.
- X
- You can also press @kbd{n}, which means ``change sign.'' It changes
- the number at the top of the stack (or the number being entered)
- from positive to negative or vice-versa: @kbd{5 n @key{RET}}.
- X
- @cindex Duplicating a stack entry
- If you press @key{RET} when you're not entering a number, the effect
- is to duplicate the top number on the stack. Consider this calculation:
- X
- @group
- @smallexample
- 1: 3 2: 3 1: 9 2: 9 1: 81
- X . 1: 3 . 1: 9 .
- X . .
- X
- X 3 RET RET * RET *
- @end smallexample
- @end group
- X
- @noindent
- (Of course, an easier way to do this would be @kbd{3 @key{RET} 4 ^},
- to raise 3 to the fourth power.)
- X
- The space-bar key (denoted @key{SPC} here) performs the same function
- as @key{RET}; you could replace all three occurrences of @key{RET} in
- the above example with @key{SPC} and the effect would be the same.
- X
- @cindex Exchanging stack entries
- Another stack manipulation key is @key{TAB}. This exchanges the top
- two stack entries. Suppose you have computed @kbd{2 @key{RET} 3 +}
- to get 5, and then you realize what you really wanted to compute
- was @cite{20 / (2+3)}.
- X
- @group
- @smallexample
- 1: 5 2: 5 2: 20 1: 4
- X . 1: 20 1: 5 .
- X . .
- X
- X 2 RET 3 + 20 TAB /
- @end smallexample
- @end group
- X
- @noindent
- Planning ahead, the calculation would have gone like this:
- X
- @group
- @smallexample
- 1: 20 2: 20 3: 20 2: 20 1: 4
- X . 1: 2 2: 2 1: 5 .
- X . 1: 3 .
- X .
- X
- X 20 RET 2 RET 3 + /
- @end smallexample
- @end group
- X
- A related stack command is @kbd{M-@key{TAB}} (hold @key{META} and type
- @key{TAB}). It rotates the top three elements of the stack upward,
- bringing the object in level 3 to the top.
- X
- @group
- @smallexample
- 1: 10 2: 10 3: 10 3: 20 3: 30
- X . 1: 20 2: 20 2: 30 2: 10
- X . 1: 30 1: 10 1: 20
- X . . .
- X
- X 10 RET 20 RET 30 RET M-TAB M-TAB
- @end smallexample
- @end group
- X
- (@bullet{}) @strong{Exercise 3.} Suppose the numbers 10, 20, and 30 are
- on the stack. Figure out how to add one to the number in level 2
- without affecting the rest of the stack. Also figure out how to add
- one to the number in level 3. @xref{RPN Answer 3, 3}. (@bullet{})
- X
- Operations like @kbd{+}, @kbd{-}, @kbd{*}, @kbd{/}, and @kbd{^} pop two
- arguments from the stack and push a result. Operations like @kbd{n} and
- @kbd{Q} (square root) pop a single number and push the result. You can
- think of them as simply operating on the top element of the stack.
- X
- @group
- @smallexample
- 1: 3 1: 9 2: 9 1: 25 1: 5
- X . . 1: 16 . .
- X .
- X
- X 3 RET RET * 4 RET RET * + Q
- @end smallexample
- @end group
- X
- @noindent
- (Note that capital @kbd{Q} means to hold down the Shift key while
- typing @kbd{q}. Remember, plain unshifted @kbd{q} is the Quit command.)
- X
- @cindex Pythagorean Theorem
- Here we've used the Pythagorean Theorem to determine the hypotenuse of a
- right triangle. Calc actually has a built-in command for that called
- @kbd{f h}, but let's suppose we can't remember the necessary keystrokes.
- We can still enter it by its full name using @kbd{M-x} notation:
- X
- @group
- @smallexample
- 1: 3 2: 3 1: 5
- X . 1: 4 .
- X .
- X
- X 3 RET 4 RET M-x calc-hypot
- @end smallexample
- @end group
- X
- All Calculator commands begin with the word @samp{calc-}. Since it
- gets tiring to type this, Calc provides an @kbd{x} key which is just
- like the regular Emacs @kbd{M-x} key except that it types the @samp{calc-}
- prefix for you:
- X
- @group
- @smallexample
- 1: 3 2: 3 1: 5
- X . 1: 4 .
- X .
- X
- X 3 RET 4 RET x hypot
- @end smallexample
- @end group
- X
- What happens if you take the square root of a negative number?
- X
- @group
- @smallexample
- 1: 4 1: -4 1: (0, 2)
- X . . .
- X
- X 4 RET n Q
- @end smallexample
- @end group
- X
- @noindent
- The notation @cite{(a, b)} represents a complex number.
- Complex numbers are more traditionally written @c{$a + b i$}
- @cite{a + b i};
- Calc can display in this format, too, but for now we'll stick to the
- @cite{(a, b)} notation.
- X
- If you don't know how complex numbers work, you can safely ignore this
- feature. Complex numbers only arise from operations that would be
- errors in a calculator that didn't have complex numbers. (For example,
- taking the square root or logarithm of a negative number produces a
- complex result.)
- X
- Complex numbers are entered in the notation shown. The @kbd{(} and
- @kbd{,} and @kbd{)} keys manipulate ``incomplete complex numbers.''
- X
- @group
- @smallexample
- 1: ( ... 2: ( ... 1: (2, ... 1: (2, ... 1: (2, 3)
- X . 1: 2 . 3 .
- X . .
- X
- X ( 2 , 3 )
- @end smallexample
- @end group
- X
- You can perform calculations while entering parts of incomplete objects.
- However, an incomplete object cannot actually participate in a calculation:
- X
- @group
- @smallexample
- 1: ( ... 2: ( ... 3: ( ... 1: ( ... 1: ( ...
- X . 1: 2 2: 2 5 5
- X . 1: 3 . .
- X .
- X (error)
- X ( 2 RET 3 + +
- @end smallexample
- @end group
- X
- @noindent
- Adding 5 to an incomplete object makes no sense, so the last command
- produces an error message and leaves the stack the same.
- X
- Incomplete objects can't participate in arithmetic, but they can be
- moved around by the regular stack commands.
- X
- @group
- @smallexample
- 2: 2 3: 2 3: 3 1: ( ... 1: (2, 3)
- 1: 3 2: 3 2: ( ... 2 .
- X . 1: ( ... 1: 2 3
- X . . .
- X
- 2 RET 3 RET ( M-TAB M-TAB )
- @end smallexample
- @end group
- X
- @noindent
- Note that the @kbd{,} (comma) key did not have to be used here.
- When you press @kbd{)} all the stack entries between the incomplete
- entry and the top are collected, so there's never really a reason
- to use the comma. It's up to you.
- X
- (@bullet{}) @strong{Exercise 4.} To enter the complex number @cite{(2, 3)},
- your friend Joe typed @kbd{( 2 , @key{SPC} 3 )}. What happened?
- (Joe thought of a clever way to correct his mistake in only two
- keystrokes, but it didn't quite work. Try it to find out why.)
- @xref{RPN Answer 4, 4}. (@bullet{})
- X
- Vectors are entered the same way as complex numbers, but with square
- brackets in place of parentheses. We'll meet vectors again later in
- the tutorial.
- X
- Any Emacs command can be given a @dfn{numeric prefix argument} by
- typing a series of @key{META}-digits beforehand. If @key{META} is
- awkward for you, you can instead type @kbd{C-u} followed by the
- necessary digits. Numeric prefix arguments can be negative, as in
- @kbd{M-- M-3 M-5} or @w{@kbd{C-u - 3 5}}. Calc commands use numeric
- prefix arguments in a variety of ways. For example, a numeric prefix
- on the @kbd{+} operator adds any number of stack entries at once:
- X
- @group
- @smallexample
- 1: 10 2: 10 3: 10 3: 10 1: 60
- X . 1: 20 2: 20 2: 20 .
- X . 1: 30 1: 30
- X . .
- X
- X 10 RET 20 RET 30 RET C-u 3 +
- @end smallexample
- @end group
- X
- For stack manipulation commands like @key{RET}, a positive numeric
- prefix argument operates on the top @var{n} stack entries at once. A
- negative argument operates on the entry in level @var{n} only. An
- argument of zero operates on the entire stack. In this example, we copy
- the second-to-top element of the stack:
- X
- @group
- @smallexample
- 1: 10 2: 10 3: 10 3: 10 4: 10
- X . 1: 20 2: 20 2: 20 3: 20
- X . 1: 30 1: 30 2: 30
- X . . 1: 20
- X .
- X
- X 10 RET 20 RET 30 RET C-u -2 RET
- @end smallexample
- @end group
- X
- @cindex Clearing the stack
- @cindex Emptying the stack
- Another common idiom is @kbd{M-0 DEL}, which clears the stack.
- (The @kbd{M-0} numeric prefix tells @key{DEL} to operate on the
- entire stack.)
- X
- @node Algebraic Tutorial, Undo Tutorial, RPN Tutorial, Basic Tutorial
- @subsection Algebraic-Style Calculations
- X
- @noindent
- If you are not used to RPN notation, you may prefer to operate the
- Calculator in ``algebraic mode,'' which is closer to the way
- non-RPN calculators work. In algebraic mode, you enter formulas
- in traditional @cite{2+3} notation.
- X
- You don't really need any special ``mode'' to enter algebraic formulas.
- You can enter a formula at any time by pressing the apostrophe (@kbd{'})
- key. Answer the prompt with the desired formula, then press @key{RET}.
- The formula is evaluated and the result is pushed onto the RPN stack.
- If you don't want to think in RPN at all, you can enter your whole
- computation as a formula, read the result from the stack, then press
- @key{DEL} to delete it from the stack.
- X
- Try pressing the apostrophe key, then @kbd{2+3+4}, then @key{RET}.
- The result should be the number 9.
- X
- Algebraic formulas use the operators @samp{+}, @samp{-}, @samp{*},
- @samp{/}, and @samp{^}. You can use parentheses to make the order
- of evaluation clear. In the absence of parentheses, @samp{^} is
- evaluated first, then @samp{*}, then @samp{/}, then finally
- SHAR_EOF
- true || echo 'restore of calc.texinfo failed'
- fi
- echo 'End of part 31'
- echo 'File calc.texinfo is continued in part 32'
- echo 32 > _shar_seq_.tmp
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-